
import Head from 'next/head'

<Head>
  <script>
    {
      `(function() {
         var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?e60fb290e204e04c5cb6f79b0ac1e697";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
       })();`
    }
  </script>
</Head>

![LangChain](https://pica.zhimg.com/50/v2-56e8bbb52aa271012541c1fe1ceb11a2_r.gif)



Git
=============================================

这篇文章展示了如何从Git仓库中加载文本文件。

从磁盘加载仓库：

```python
from git import Repo

repo = Repo.clone_from(
    "https://github.com/hwchase17/langchain", to_path="./example_data/test_repo1"
)

# 获取当前分支
branch = repo.head.reference
```

使用GitLoader加载：

```python
from langchain.document_loaders import GitLoader

loader = GitLoader(repo_path="./example_data/test_repo1/", branch=branch)

data = loader.load()
```

输出个别文件的内容：

```python
print(data[0])
```

从远程地址克隆仓库：

```python
loader = GitLoader(
    clone_url="https://github.com/hwchase17/langchain",
    repo_path="./example_data/test_repo2/",
    branch="master",
)

data = loader.load()
```

使用过滤器加载指定类型的文件：

```python
from langchain.document_loaders import GitLoader

# 比如只加载python文件
loader = GitLoader(repo_path="./example_data/test_repo1/", file_filter=lambda file_path: file_path.endswith(".py"))
```